<?php
/**
 * Class to handle Bootstrap Carousel
 *
 * @author		Joachim Ruf, Loresoft Software (http://www.loresoft.de)
 * @license		New BSD License
 * @version		Class for Bootstrap v2.3.2
 *
 * */


Class Bootstrap_Carousel_Handler
{
	private $arrItem			= array();
	private $useControlLeft		= NULL;
	private $useControlRight	= NULL;
	private $useIndicator		= false;
	private $activeItem			= 0;

	/**
	 *
	 * */
	function __construct () {

	}


	/**
	 * Erstellt einen Control-Left-Button
	 * @param string $_text		: Beschriftung des Buttons
	 * */
	public function useControlLeft ($_text = '&lsaquo;') {
		$this->useControlLeft = $_text;
	}


	/**
	 * Erstellt einen Control-Right-Button
	 * @param string $_text		: Beschriftung des Buttons
	 * */
	public function useControlRight ($_text = '&rsaquo;') {
		$this->useControlRight = $_text;
	}


	/**
	 * Erstellt Indikatoren zu den Entries
	 * @param string $_text		: Beschriftung des Buttons
	 * */
	public function useIndicator () {
		$this->useIndicator = true;
	}



	/**
	 * Erstellt ein Carousel-Item
	 * @param string $_content		: Auszugebender Content
	 * @return string
	 * */
	public function addItem ($_content, $_setAsActive = false) {
		if ($_setAsActive === true) {
			$this->activeItem = count($this->arrItem);
		}
		$this->arrItem[] = $_content;
	}


	public function display ($_id) {
		$contentIndicator	= '';
		$contentItem		= '';

		if (!count($this->arrItem)) {
			return NULL;
		}

		foreach ($this->arrItem as $key => $val) {
			if ($this->useIndicator) {
				$active = ($this->activeItem === $key) ? ' class="active"' : '';
				$contentIndicator .= '<li data-target="#'.$_id.'" data-slide-to="'.$key.'"'.$active.'></li>';
			}

			$active = ($this->activeItem === $key) ? ' active' : '';
			$contentItem .= '<div class="item'.$active.'">
								'.$val.'
							</div>';
		}

		if ($this->useIndicator) {
			$contentIndicator = '<ol class="carousel-indicators">'.$contentIndicator.'</ol>';
		}
		$controlLeft	= ($this->useControlLeft !== NULL) ? '<a class="carousel-control left" href="#'.$_id.'" data-slide="prev">'.$this->useControlLeft.'</a>' : '';
		$controlRight	= ($this->useControlRight !== NULL) ? '<a class="carousel-control right" href="#'.$_id.'" data-slide="next">'.$this->useControlRight.'</a>' : '';

		return '<div id="'.$_id.'" class="carousel slide">
					'.$contentIndicator.'
					<div class="carousel-inner">
						'.$contentItem.'
					</div>
					'.$controlLeft.'
					'.$controlRight.'
				</div>';
	}


}


?>